package com.spzx.JUC2.test3;

public class Number {
    private static int i = 0;
    public synchronized void add() throws InterruptedException {
        while (i != 0) {
            this.wait();
        }
        i++;
        System.out.println(Thread.currentThread().getName() + "=" + i);

        //this.notify();
        this.notifyAll();
    }

    public synchronized void minus() throws InterruptedException {
        while (i !=1) {
            this.wait();
        }
        i--;
        System.out.println(Thread.currentThread().getName() + "=" + i);

        //this.notify();
        this.notifyAll();
    }
}
